using System.ComponentModel.DataAnnotations;

namespace KnowledgeQA.Models.Entities
{
    /// <summary>
    /// 聊天消息实体类
    /// </summary>
    public class ChatMessage : BaseEntity
    {
        /// <summary>
        /// 会话ID
        /// </summary>
        public int SessionId { get; set; }

        /// <summary>
        /// 聊天会话
        /// </summary>
        public virtual ChatSession Session { get; set; } = null!;

        /// <summary>
        /// 消息类型（User、Assistant、System）
        /// </summary>
        [Required]
        [MaxLength(20)]
        public string MessageType { get; set; } = "User";

        /// <summary>
        /// 消息内容
        /// </summary>
        [Required]
        public string Content { get; set; } = string.Empty;

        /// <summary>
        /// 消息序号
        /// </summary>
        public int MessageIndex { get; set; }

        /// <summary>
        /// 父消息ID（用于回复关系）
        /// </summary>
        public int? ParentMessageId { get; set; }

        /// <summary>
        /// 父消息
        /// </summary>
        public virtual ChatMessage? ParentMessage { get; set; }

        /// <summary>
        /// 回复消息列表
        /// </summary>
        public virtual ICollection<ChatMessage> Replies { get; set; } = new List<ChatMessage>();

        /// <summary>
        /// 消息状态（Pending、Processing、Completed、Failed）
        /// </summary>
        [MaxLength(20)]
        public string Status { get; set; } = "Completed";

        /// <summary>
        /// 处理时间（毫秒）
        /// </summary>
        public long? ProcessingTime { get; set; }

        /// <summary>
        /// 使用的模型名称
        /// </summary>
        [MaxLength(100)]
        public string? ModelName { get; set; }

        /// <summary>
        /// 模型参数（JSON格式存储）
        /// </summary>
        [MaxLength(1000)]
        public string? ModelParameters { get; set; }

        /// <summary>
        /// 检索到的文档块ID列表（JSON格式存储）
        /// </summary>
        [MaxLength(2000)]
        public string? RetrievedChunkIds { get; set; }

        /// <summary>
        /// 相关度评分列表（JSON格式存储）
        /// </summary>
        [MaxLength(1000)]
        public string? RelevanceScores { get; set; }

        /// <summary>
        /// 错误信息
        /// </summary>
        [MaxLength(1000)]
        public string? ErrorMessage { get; set; }

        /// <summary>
        /// 用户反馈（Like、Dislike、None）
        /// </summary>
        [MaxLength(20)]
        public string UserFeedback { get; set; } = "None";

        /// <summary>
        /// 用户反馈备注
        /// </summary>
        [MaxLength(500)]
        public string? FeedbackNote { get; set; }
    }
} 